﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YmtSystem.CrossCutting;
using YmtAuth.Domain.Shard;
namespace YmtAuth.Domain.Model.User
{
    public class YmtUser : Entity
    {
        public override object _id { get;protected set; }
        public Dictionary<string, object> Value { get; set; }
        public static readonly YmtUser Empty = new YmtUser { _id = -1, Value = new Dictionary<string, object> { } };
        public static YmtUser Create(int userId)
        {
            return new YmtUser { _id = userId, Value = new Dictionary<string, object> { } };
        }
       
        /// <summary>
        /// 生成用户数据
        /// </summary>     
        public static YmtUser Create(Dictionary<string, object> uData)
        {
            var uId = Convert.ToInt32(uData.TryGetV(YmtUserKey.uId, YmtUserKey.InvalidUId));
            if (uId == YmtUserKey.InvalidUId)
            {
                return Empty;
            }
            //var data = new Dictionary<string, object> 
            //{
            //    {"iUserId",uId},
            //    {"sLoginId",uData.TryGetV(YmtUserKey.sLoginId,string.Empty)},
            //    {"sTradingPassword",uData.TryGetV(YmtUserKey.sTradingPassword,string.Empty)},
            //    {"sLoginEmail",uData.TryGetV(YmtUserKey.sLoginEmail,string.Empty)}
            //};
            //按不同认证策略生成用户
            //排除基础数据
            var tmpUdata = uData.Where(e => e.Key != "sType" && e.Key != "sPassword").ToDictionary(e => e.Key, e => e.Value);
            return new YmtUser
            {
                _id = uId,
                Value = tmpUdata
            };
        }
    }
}
